$(function() {
	$('.produce-dh .dh').on('click', function() {
		layer.open({
			title: "",
			content: '所兑话费将充值到您当前 13800000000的手机号上，是否确定兑换？',
			btn: ['是', '否'],
			shadeClose: true
		});
	});

	$(function() {
		if(($("#name").val() != "") && ($("#mobile").val() != "") && ($("#showCityPicker").val() != "") && ($("#adres").val() != "")) {
			$(".sub").css({
				"background": "#26bced",
				"color": "#fff"
			});
		} else {
			$(".sub").css({
				"background": "#83ddff",
				"color": "#c1edfe"
			});
		}

		//地区弹窗
		(function($, doc) {
			$.init();
			$.ready(function() {
				var cityPicker = new $.PopPicker({
					layer: 3
				});
				cityPicker.setData(city);
				var showCityPickerButton1 = doc.getElementById('showCityPicker');
				showCityPickerButton1.addEventListener('tap', function(event) {
					cityPicker.show(function(items) {
						showCityPickerButton1.value = items[0].text + " " + items[1].text + " " + items[2].text;
					});
				}, false);
			});
		})(mui, document);

		//		提交高亮显示
		$("#name").blur(function() {
			exist();
		});
		$("#mobile").blur(function() {
			exist();
		});
		$("#showCityPicker").blur(function() {
			exist();
		});
		$("#adres").keyup(function() {
			exist();
		});

		function exist() {
			var num = 0;
			if($("#name").val() != "") {
				num++;
			}
			if($("#mobile").val() != "") {
				num++;
			}
			if($("#showCityPicker").val() != "") {
				num++;
			}
			if($("#adres").val() != "") {
				num++;
			}
			if(num == 4) {
				$(".sub").css({
					"background": "#26bced",
					"color": "#fff"
				});
			} else {
				$(".sub").css({
					"background": "#83ddff",
					"color": "#c1edfe"
				});
			}
		}
		var handler = false;
		//		//      跳转地址star
		var handler = false;
		$('#submit').on('click', function() {
			var sUser = $.trim($("#name").val()),
				sPhone = $.trim($('#mobile').val()),
				sCont = $.trim($('#showCityPicker').val()),
				sAddress = $.trim($('#adres').val()),
				oData = $(this).data(),
				sSession = oData.sid,
				sId = oData.id;
			if(!sUser) {
				layer.alert('请输入收货人信息！');
				return false;
			}
			if(!/^((1[3,8][0-9])|(15[012356789])|(14[5,7,9])|(17[0,1,3,5,6,7,8]))\d{8}$/.test(sPhone)) {
				layer.alert('请输入正确的收货人电话！');
				return false;
			}
			if(!sCont) {
				layer.alert('请输入收货人城市地址！');
				return false;
			}
			if(!sAddress) {
				layer.alert('请输入收货人详细地址信息！');
				return false;
			}
			var args = {
				id: sId,
				n: 1,
				link_user: sUser,
				link_phone: $("#mobile").val(),
				link_count: $("#showCityPicker").val(),
				link_address: $("#adres").val()
			};
			if (handler) {return false}
			handler = true;
			$.post("/tea/score/post/buy/?sessionid=" + sSession + "", args, function(rsp) {
				handler = false;
				if(rsp.error) {
					window.location.href = "/tea/score/result/?id=" + sId + "&error=" + rsp.error + "&sessionid=" + sSession + "";
				} else {
					window.location.href = "/tea/score/result/?id=" + sId + "&sessionid=" + sSession + "";
				}

			}, 'json');
		});

	})

})